//
//  XClockInModel.m
//  iPlan
//
//  Created by 侯伟 on 2021/8/29.
//

#import "XClockInModel.h"

@implementation XClockInModel

+ (nullable NSString *)primaryKey{
    return @"id";
}

+ (NSArray *)ignoredProperties {
    return @[@"todayState"];
}

//+ (NSDictionary *)linkingObjectsProperties {
//      return @{@"record":[RLMPropertyDescriptor descriptorWithClass:NSClassFromString(@"XClockInModel") propertyName:@"records"]};
//}

- (instancetype)init{
    self = [super init];
    if (self) {
        _id = [[NSDate date] timeIntervalSince1970];
    }
    return self;
}


- (id)mutableCopyWithZone:(nullable NSZone *)zone{
    NSString* json = [self yy_modelToJSONObject];
    return [XClockInModel yy_modelWithJSON:json];
}

- (BOOL)todayState{
    for (XClockInDate* date in self.records) {
        NSString* dateStr = [date.date stringYearMonthDay];
        NSString* todayStr = [[NSDate date] stringYearMonthDay];
        if([dateStr isEqualToString:todayStr]){
            return YES;
        }
    }
    return NO;
}

@end
